function forMatNum(num){
	return num<10?'0'+num:num+'';
}

function initDays(year,month){
	let totalDays=new Date(year,month,0).getDate();
	let dates=[];
	for(let d=1;d<=totalDays;d++){
		dates.push(forMatNum(d));
	};
	return dates;
}
function initPicker(start,end,mode="date",step,value,flag) {
	let aToday=new Date();
	let tYear,tMonth,tDay,tHours,tMinutes,tSeconds,defaultVal=[];
	let initstartDate=new Date(start);
	let endDate=new Date(end);
	if(start>end){
		initstartDate=new Date(end);
		endDate=new Date(start);
	};
	let startYear=initstartDate.getFullYear();
	let startMonth=initstartDate.getMonth()+1;
	let endYear=endDate.getFullYear();
	let years=[],months=[],days=[],hours=[],minutes=[],seconds=[],returnArr=[];
	let curMonth=flag?value[1]*1:(value[1]+1);
	let totalDays=new Date(startYear,curMonth,0).getDate();
	for(let s=startYear;s<=endYear;s++){
		years.push(s+'');
	};
	for(let m=1;m<=12;m++){
		months.push(forMatNum(m));
	};
	for(let d=1;d<=totalDays;d++){
		days.push(forMatNum(d));
	}
	for(let h=8;h<21;h++){
		hours.push(forMatNum(h));
	}
	for(let m=0;m<60;m+=step*30){
		minutes.push(forMatNum(m));
	}
	for(let s=0;s<60;s++){
		seconds.push(forMatNum(s));
	}
	if(flag){
		returnArr=[years.indexOf(value[0]),months.indexOf(value[1]),days.indexOf(value[2]),hours.indexOf(value[3]),minutes.indexOf(value[4]),seconds.indexOf(value[5])]
	};
	switch(mode){
		case "date":
			if(flag){
				defaultVal=[returnArr[0],returnArr[1],returnArr[2]];
				return {years,months,days,defaultVal}
			}else{
				return {years,months,days}
			}
			break;
		case "yearMonth":
			if(flag){
				defaultVal=[returnArr[0],returnArr[1]];
				return {years,months,defaultVal}
			}else{
				return {years,months}
			}
			break;
		case "dateTime":
			if(flag){
				defaultVal=returnArr;
				return {years,months,days,hours,minutes,seconds,defaultVal}
			}else{
				return {years,months,days,hours,minutes,seconds}
			}
			break;
		case "time":
			if(flag){
				defaultVal=[returnArr[3],returnArr[4],returnArr[5]];
				return {hours,minutes,seconds,defaultVal}
			}else{
				return {hours,minutes,seconds}
			}
			break;			
	}
}
export{
	initDays,
	initPicker
}
//格式化时间 
// 对Date的扩展，将 Date 转化为指定格式的String   
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，   
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)   
// 例子：   
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423   
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18  
Date.prototype.Format =function(fmt)   
{ //author: meizz   
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日   
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}

